package javacode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

/**
 * 通过代码模拟珠子玩法的概率问题，实际证明赌博必输 只要你玩的次数够大
 * 
*/
public class Mozhuzic {

    private List<Cates> list = new ArrayList<>();
    private List<Zhuzi> zhuzis = new ArrayList<>();
    private List<Integer> out = new ArrayList<>();


    public static void main(String[] agrs) {
        System.err.println("test");
        // 840 100 831 60 822 50 750 40 741 30 732 20 660 20 651 10 642 5 633 15 552 10
        // 444 5 345 -20
        Mozhuzic mozhuzic = new Mozhuzic();
        System.out.println("增加珠子赔率");
        mozhuzic.addCate(840, 100);
        mozhuzic.addCate(831, 60);
        mozhuzic.addCate(822, 50);
        mozhuzic.addCate(750, 40);
        mozhuzic.addCate(741, 30);
        mozhuzic.addCate(732, 20);
        mozhuzic.addCate(660, 20);
        mozhuzic.addCate(651, 10);
        mozhuzic.addCate(642, 5);
        mozhuzic.addCate(633, 15);
        mozhuzic.addCate(552, 10);
        mozhuzic.addCate(543, -20);
        mozhuzic.addCate(444, 5);
        // 红 黄 蓝 三色珠 各8个

        System.out.println("添加24个珠子");
        // 添加24个珠子
        for (int i = 0; i < 24; i++) {

            if (i < 8) {
                mozhuzic.zhuzis.add(Zhuzi.red);
            } else if (i < 16) {
                mozhuzic.zhuzis.add(Zhuzi.green);
            } else {
                mozhuzic.zhuzis.add(Zhuzi.blue);
            }
        }

        // System.out.println("摸12个珠子 玩一下 ");
        Random random = new Random();
        int a = 0;
       
        while (a < 12) {
            int nextint = random.nextInt(24);
           
            if (mozhuzic.out.contains(nextint)) {
                continue;
            }
            mozhuzic.out.add(nextint);
            System.err.println("next:"+nextint);
            a++;
            
        }

        int zuhe = mozhuzic.getCaa();

        System.err.println("zuhe" + zuhe);

        for (int i = 0; i < mozhuzic.list.size(); i++) {
            if (mozhuzic.list.get(i).getZuhe() == zuhe) {
                System.err.println("赔率：" + mozhuzic.list.get(i).getWeight());
            }
        }


    }

    private int getCaa() {

        int m = 0,n = 0,p = 0;
        for (int i = 0; i < out.size(); i++) {
            if (out.get(i) < 8) {
                m++;
            }else if (out.get(i)<16) {
                n++;
            }else{   p++;
            }
        }
        System.err.println(m);
        System.err.println(n);
        System.err.println(p);
        int[] a = {m,n,p};
        Arrays.sort(a);
        System.err.println(a);

        return a[ 0] + a[1]*10 +a[2]*100;
    }

    private void addCate(int cate, int weight) {
        Cates m = new Cates();
        m.setWeight(weight);
        m.setZuhe(cate);
        list.add(m);
    }

}
